--事件
EventData = class()
function EventData:ctor(eventType,data)
	self.type = eventType
	self.data = data
end

--事件发送类
EventDispatcher = class("EventDispatcher")
function EventDispatcher:ctor()
	self.eventWatcherDict = {}
end
--添加侦听
function EventDispatcher:Add(eventType,listener, owner)
--[[	if utils.isEmpty(eventType) then
	 	error("eventType or listener is empty") 
	end]]
	local eventWatcher = self.eventWatcherDict[eventType]
	if(eventWatcher == nil) then 
		eventWatcher = event(eventType, true)
		self.eventWatcherDict[eventType] = eventWatcher
	end
	eventWatcher:Add(listener, owner)
end
--移除侦听
function EventDispatcher:Remove(eventType,listener, owner)
	local eventWatcher = self.eventWatcherDict[eventType]
	if eventWatcher ~= nil then 
		eventWatcher:Remove(listener, owner)
	end
end
--移除所有侦听
function EventDispatcher:removeAllEventListener(eventType)
	if eventType~=nil then
		self.eventWatcherDict[eventType] = nil
	else
		self.eventWatcherDict = {}
	end
end
--发送事件
function EventDispatcher:Dispatch(eventType,data)
	local eventWatcher = self.eventWatcherDict[eventType]
	if eventWatcher then
		local event = EventData.new(eventType,data)
		event.target = self
		eventWatcher(event)
	end
end
--发送事件
function EventDispatcher:dispatchEvent(event)
	local eventWatcher = self.eventWatcherDict[event.type]
	if eventWatcher then
		eventWatcher(event)
	end
end

function EventDispatcher:Dump(eventType)
	for k, v in pairs(self.eventWatcherDict) do
		print('-------------', k, '-------------')
		v:Dump()
	end
end

function EventDispatcher:Clear()
	for k, v in pairs(self.eventWatcherDict) do
		v:Clear()
	end

	self.eventWatcherDict = {}
end


